﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAL;

namespace BLL
{
    public class ValidateUser
    {
        public DAL.User validate(DAL.User user)
        {
            DAL.User retrievedUser = user.getUserById(user);           

            if ( Util.Common.CommonUtility.Decrypt(retrievedUser.Password) ==user.Password)
            {
                return retrievedUser;
            }
            else
                throw new Exception("Wrong Password");
        }
        public List<Role> getRoles()
        {
            DAL.Role l_role = new DAL.Role();
            return l_role.getRoles();
        }

        public User ChangePassword(User user)
        {
            DAL.User retrievedUser = user.getUserById(user);

            if (Util.Common.CommonUtility.Decrypt(retrievedUser.Password) == user.Password)
            {
                try
                {
                    retrievedUser.confirmPassword = Util.Common.CommonUtility.Encrypt(user.confirmPassword);
                    retrievedUser.Save();
                    return retrievedUser;
                }
                catch (Exception ex)
                {
                    
                    throw ex;
                }
            }
            else
                throw new Exception("Wrong Password");
        }
    }
}
